<?php
class Router {
	
	public static function parse($url,$request){
		
		if(true ){//!isset($_SESSION['email'])){
			$url = trim($url,'/');			
			$params = explode('/',$url);
			
			$request->controller = isset($params[1]) ? $params[1] : 'Acceuil';
			$request->action = isset($params[2]) ? $params[2] : 'index';
			$request->params = array_slice($params,3);
            if($request->controller=='index')
                $request->controller='Acceuil';
			
		} else {
			$url = trim($url,'/');
			$params = explode('/',$url);
			if(!isset($params[1])){
				if($_SESSION['type_utilisateur']=="Restaurant")
					$request->controller = 'restaurant';
				else if($_SESSION['type_utilisateur']=="Particulier")
					$request->controller = 'particulier';
				else if($_SESSION['type_utilisateur']=="Hotel")
					$request->controller = 'hotel';
                else if($_SESSION['type_utilisateur']=="Fournisseur")
                    $request->controller = 'fournisseur';
                else if($_SESSION['type_utilisateur']=="Traiteur")
                    $request->controller = 'traiteur';
                else if($_SESSION['type_utilisateur']=="admin")
                    $request->controller = "admin";
			} else {
				$request->controller = isset($params[1]) ? $params[1] : '';
			}
			$request->action = isset($params[2]) ? $params[2] : 'index';
			$request->params = array_slice($params,3);
		}
	}
}